package com.mgm.result;

/**
 * 后天返回前端消息体
* @ClassName: IMessage 
* @Description: TODO(...) 
* @author Andy Zhang
* @date 2018年6月21日 下午11:50:55 
*
 */
public class IMessage {
	
	private int code;
	private int status;
	private String msg;
	
	/** 通用异常
	public static IMessage SUCCESS = new IMessage(1, 200, "Success"); //Successful operation
	public static IMessage BAD_REQUEST = new IMessage(0, 400, "Bad request"); //Bad request
	public static IMessage SERVER_ERROR = new IMessage(0, 500, "Server error"); //Server error
	*/
	
	private IMessage(int code, int status, String msg) {
		this.code = code;
		this.status = status;
		this.msg = msg;
	}

	public static IMessage error(int status, String msg) {
		return new IMessage(0, status, msg);
	}
	
	public static IMessage errorCode(int code, String msg) {
		return new IMessage(code, 200, msg);
	}
	
	public static IMessage error(String msg) {
		return new IMessage(0, 200, msg==null ? "success" : msg);
	}
	
	public static IMessage success() {
		return new IMessage(1, 200, "success");
	}
	
	public boolean isSuccess() {
		return this.code==1;
	}

	public int getCode() {
		return code;
	}


	public void setCode(int code) {
		this.code = code;
	}


	public int getStatus() {
		return status;
	}


	public void setStatus(int status) {
		this.status = status;
	}


	public String getMsg() {
		return msg;
	}


	public void setMsg(String msg) {
		this.msg = msg;
	}
 
}
